package org.wtframework.platform.web.mvc.action.impl;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.openredhead.springx.core.server.model.IUser;
import org.openredhead.springx.core.web.mvc.annotation.ActionView;
import org.openredhead.springx.core.web.mvc.support.ActionValueAssistant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.wtframework.platform.server.manager.impl.UserManager;

@Controller
public class BackUIActionController {

	@Autowired
	private UserManager userManager;

	/*
	 * author：wei 框架一
	 */
	// 测试：后台主页
	@RequestMapping("/newUI")
	public String newUI(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap, ActionValueAssistant actionValueAssistant) {

		actionValueAssistant.addToModelMap(modelMap);

		modelMap.put("user", userManager.load(1L));
		System.out.println("111");
		return "jsp/newUI/index";
	}

	// 测试：frame
	@RequestMapping("/frame")
	public String frame(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap, ActionValueAssistant actionValueAssistant) {

		actionValueAssistant.addToModelMap(modelMap);

		modelMap.put("user", userManager.load(1L));

		return "jsp/newUI/frame";
	}

	// 测试：ipage1
	@RequestMapping("/ipage1")
	public String ipage1(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap, ActionValueAssistant actionValueAssistant) {

		actionValueAssistant.addToModelMap(modelMap);

		modelMap.put("user", userManager.load(1L));

		return "jsp/newUI/iPage_1";
	}

	// 测试：list
	@RequestMapping("/list")
	public String list(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap, ActionValueAssistant actionValueAssistant) {

		actionValueAssistant.addToModelMap(modelMap);

		modelMap.put("user", userManager.load(1L));

		return "jsp/newUI/list";
	}

	// 测试：modal
	@RequestMapping("/modal")
	public String modal(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap, ActionValueAssistant actionValueAssistant) {

		actionValueAssistant.addToModelMap(modelMap);

		modelMap.put("user", userManager.load(1L));

		return "jsp/newUI/modal";
	}

	// 测试：table
	@RequestMapping("/table")
	public String table(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap, ActionValueAssistant actionValueAssistant) {

		actionValueAssistant.addToModelMap(modelMap);

		modelMap.put("user", userManager.load(1L));

		return "jsp/newUI/table";
	}

	// 测试：button
	@RequestMapping("/button")
	public String button(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap, ActionValueAssistant actionValueAssistant) {

		actionValueAssistant.addToModelMap(modelMap);

		modelMap.put("user", userManager.load(1L));

		return "jsp/newUI/button";
	}

	// 测试：dialog
	@RequestMapping("/dialog")
	public String dialog(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap, ActionValueAssistant actionValueAssistant) {

		actionValueAssistant.addToModelMap(modelMap);

		modelMap.put("user", userManager.load(1L));

		return "jsp/newUI/dialog";
	}

	// 测试：calendar
	@RequestMapping("/calendar")
	public String calendar(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap, ActionValueAssistant actionValueAssistant) {

		actionValueAssistant.addToModelMap(modelMap);

		modelMap.put("user", userManager.load(1L));

		return "jsp/newUI/calendar";
	}

	// 测试：validator
	@RequestMapping("/validator")
	public String validator(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap, ActionValueAssistant actionValueAssistant) {

		actionValueAssistant.addToModelMap(modelMap);

		modelMap.put("user", userManager.load(1L));

		return "jsp/newUI/validator";
	}

	/*
	 * 框架二 author：wei
	 */
	@RequestMapping("/adminUI")
	public String adminUI(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap, ActionValueAssistant actionValueAssistant) {

		return "jsp/adminUI/index";
	}

	@RequestMapping("/@/aa")
	public ModelAndView jsp1(ModelMap modelMap, ActionValueAssistant actionValueAssistant) {

		System.out.println(actionValueAssistant.get(Integer.class, "id"));

		return new ModelAndView("jsp/test1");

	}

	// testActionController/jspc
	@RequestMapping("/@")
	public @ResponseBody
	IUser jspc(ModelMap modelMap, ActionValueAssistant actionValueAssistant) {

		// System.out.println(actionValueAssistant.get(Integer.class, "id"));

		return userManager.load(1L);

	}

	@RequestMapping("/@")
	public @ResponseBody
	Date date(ModelMap modelMap, ActionValueAssistant actionValueAssistant) {

		return new Date();

	}

	@RequestMapping("/@/{bool}")
	@ActionView(successView = "/success", failView = "/fail")
	public boolean bool(@PathVariable String bool, ModelMap modelMap, ActionValueAssistant actionValueAssistant) {

		System.out.println("bool: " + bool);

		modelMap.addAttribute("bool", bool);

		return Boolean.parseBoolean(bool);

	}

}
